package com.atguigu.service.impl;

import com.atguigu.dao.ProjectDao;
import com.atguigu.dao.impl.ProjectDaoImpl;
import com.atguigu.pojo.Project;
import com.atguigu.pojo.ProjectModule;
import com.atguigu.pojo.ProjectModuleType;
import com.atguigu.service.ProjectModuleService;
import com.atguigu.service.ProjectModuleTypeService;
import com.atguigu.service.ProjectService;

import java.util.LinkedHashSet;
import java.util.List;

public class ProjectServiceImpl implements ProjectService {
    ProjectDao projectDao=new ProjectDaoImpl();
    @Override
    public void addProject(Project project) {
        projectDao.addProject(project);
    }

    @Override
    public void updateProject(Project project) {
        projectDao.updateProject(project);
    }

    @Override
    public void deleteProjectById(String id) {
        projectDao.deleteProjectById(id);
    }

    @Override
    public Project queryProjectByProjectName(String projectName) {
        Project project=projectDao.queryProjectByProjectName(projectName);
        return project;
    }

    @Override
    public Project queryProjectByProjectId(String id) {
        Project project=projectDao.queryProjectByProjectId(id);
        return project;
    }

    @Override
    public List<Project> queryProjects() {
        List<Project> projects=projectDao.queryProjects();
        return projects;
    }

    @Override
    public LinkedHashSet<Project> queryProjectsByModuleTypeName(String moduleTypeName){
        ProjectModuleTypeService projectModuleTypeService=new ProjectModuleTypeServiceImpl();
        ProjectModuleService projectModuleService=new ProjectModuleServiceImpl();
        ProjectService projectService=new ProjectServiceImpl();

        ProjectModuleType projectModuleType=projectModuleTypeService.queryProjectModuleTypeByName(moduleTypeName);
        List<ProjectModule> projectModules= projectModuleService.queryProjectModulesByProjectModuleTypeId(projectModuleType.getId());
        LinkedHashSet<Project> projects=new LinkedHashSet<>();
        for (ProjectModule projectModule:projectModules){
            Project project= projectService.queryProjectByProjectId(projectModule.getProjectId());
            projects.add(project);
        }
        return projects;
    }
    @Override
    public LinkedHashSet<Project> queryProjectsByModuleTypeId(String moduleTypeId){
        ProjectModuleTypeService projectModuleTypeService=new ProjectModuleTypeServiceImpl();
        ProjectModuleService projectModuleService=new ProjectModuleServiceImpl();
        ProjectService projectService=new ProjectServiceImpl();


        List<ProjectModule> projectModules= projectModuleService.queryProjectModulesByProjectModuleTypeId(moduleTypeId);
        LinkedHashSet<Project> projects=new LinkedHashSet<>();
        for (ProjectModule projectModule:projectModules){
            Project project= projectService.queryProjectByProjectId(projectModule.getProjectId());
            projects.add(project);
        }
        return projects;
    }
}
